<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="/WEB-INF/jsp/common/header.jsp" %>

<div class="row">
    <!-- 左侧博客列表 -->
    <div class="col-md-8">
        <div class="card shadow mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">
                    分类：${category}
                    <c:if test="${not empty blogList}">
                        <span class="badge bg-light text-dark ms-2">${blogList.size()}篇博客</span>
                    </c:if>
                </h5>
            </div>
            <div class="card-body">
                <c:choose>
                    <c:when test="${not empty blogList}">
                        <div class="list-group">
                            <c:forEach var="blog" items="${blogList}">
                                <a href="${pageContext.request.contextPath}/blog/view?id=${blog.id}" class="list-group-item list-group-item-action">
                                    <div class="d-flex w-100 justify-content-between">
                                        <h5 class="mb-1">${blog.title}</h5>
                                        <small class="text-muted">
                                            <fmt:formatDate value="${blog.createTime}" pattern="yyyy-MM-dd" />
                                        </small>
                                    </div>
                                    <p class="mb-1 text-truncate">
                                        ${blog.content.replaceAll("#", "").replaceAll("\\*", "").replaceAll("`", "")}
                                    </p>
                                    <div class="d-flex justify-content-between align-items-center">
                                        <small class="text-muted">
                                            <i class="fas fa-user me-1"></i>${blog.authorName}
                                        </small>
                                        <small class="text-muted">
                                            <i class="fas fa-eye me-1"></i>${blog.viewCount}
                                        </small>
                                    </div>
                                </a>
                            </c:forEach>
                        </div>
                    </c:when>
                    <c:otherwise>
                        <div class="alert alert-info text-center">
                            <p class="mb-0">该分类下暂无博客</p>
                            <a href="${pageContext.request.contextPath}/blog/list" class="btn btn-primary mt-3">
                                <i class="fas fa-home me-1"></i>返回首页
                            </a>
                        </div>
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
    </div>
    
    <!-- 右侧热门博客 -->
    <div class="col-md-4">
        <!-- 博客分类 -->
        <div class="card shadow mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">博客分类</h5>
            </div>
            <div class="card-body">
                <div class="list-group">
                    <a href="${pageContext.request.contextPath}/blog/category?category=技术" class="list-group-item list-group-item-action ${category == '技术' ? 'active' : ''}">技术</a>
                    <a href="${pageContext.request.contextPath}/blog/category?category=生活" class="list-group-item list-group-item-action ${category == '生活' ? 'active' : ''}">生活</a>
                    <a href="${pageContext.request.contextPath}/blog/category?category=旅游" class="list-group-item list-group-item-action ${category == '旅游' ? 'active' : ''}">旅游</a>
                    <a href="${pageContext.request.contextPath}/blog/category?category=艺术" class="list-group-item list-group-item-action ${category == '艺术' ? 'active' : ''}">艺术</a>
                </div>
            </div>
        </div>
        
        <!-- 热门博客 -->
        <div class="card shadow">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">热门博客</h5>
            </div>
            <div class="card-body">
                <c:choose>
                    <c:when test="${not empty hotBlogs}">
                        <ul class="list-group">
                            <c:forEach var="blog" items="${hotBlogs}" varStatus="status">
                                <a href="${pageContext.request.contextPath}/blog/view?id=${blog.id}" class="list-group-item list-group-item-action">
                                    <div class="d-flex w-100 justify-content-between align-items-center">
                                        <h6 class="mb-1">
                                            <span class="badge bg-danger me-2">${status.index + 1}</span>
                                            ${blog.title}
                                        </h6>
                                    </div>
                                    <div class="d-flex justify-content-between align-items-center">
                                        <small class="text-muted">
                                            <span class="badge bg-${blog.category == '技术' ? 'primary' : 
                                                            blog.category == '生活' ? 'success' : 
                                                            blog.category == '旅游' ? 'info' : 
                                                            blog.category == '艺术' ? 'warning' : 'secondary'}">
                                                ${blog.category}
                                            </span>
                                        </small>
                                        <small class="text-muted">
                                            <i class="fas fa-eye me-1"></i>${blog.viewCount}
                                        </small>
                                    </div>
                                </a>
                            </c:forEach>
                        </ul>
                    </c:when>
                    <c:otherwise>
                        <p class="text-center text-muted my-3">暂无热门博客</p>
                    </c:otherwise>
                </c:choose>
                <div class="d-grid gap-2 mt-3">
                    <a href="${pageContext.request.contextPath}/blog/hot" class="btn btn-outline-primary">
                        查看更多热门博客
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<%@ include file="/WEB-INF/jsp/common/footer.jsp" %> 